package com.lucker.service.caipiaoopencodebackup;

import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.lucker.cds.model.CustomCaiPiaoOpencodeBackup;
import com.lucker.common.util.DateTimeUtil;
import com.lucker.ds.mapper.BaseCustomMapper;
import com.lucker.ds.model.CaiPiaoOpencode;
import com.lucker.ds.model.CaiPiaoOpencodeBackup;
import com.lucker.service.BaseServiceImpl;
import com.lucker.service.caipiao.CaiPiaoOpencodeService;

@Service
public class CaiPiaoOpencodeBackupServiceImpl extends BaseServiceImpl<CaiPiaoOpencodeBackup, CustomCaiPiaoOpencodeBackup, Long> implements CaiPiaoOpencodeBackupService {

	@Autowired
	CaiPiaoOpencodeService caiPiaoOpencodeService;
	
	@Override
	public BaseCustomMapper<CustomCaiPiaoOpencodeBackup, Long> getCustomMapper() {
		return null;
	}
	
	@Transactional
	public void updateOpen(List<CaiPiaoOpencodeBackup> plist) {
		
		for(CaiPiaoOpencodeBackup p : plist) {
			
			String issueNo = p.getIssueno();
			String cai_id = p.getCaiId();
			
			CaiPiaoOpencode code = new CaiPiaoOpencode();
			code.setIssueno(issueNo);
			code.setCaiId(cai_id);
			
			int count = caiPiaoOpencodeService.queryAllCount(code);
			if(count < 1) {
				try {
					code = new CaiPiaoOpencode();
					BeanUtils.copyProperties(code, p);
					code.setId(null);
					code.setExtend3(DateTimeUtil.getDate(DateTimeUtil.FORMAT_LONGTIME));
					caiPiaoOpencodeService.add(code, false);
					//getLOGGER().error("==================================================== {}" , JSONObject.toJSONString(code));
				}catch (Exception e) {
					e.printStackTrace();
				}
			}
			
			//
			CaiPiaoOpencodeBackup pt = queryById(p.getId());
			pt.setNumber9("2");
			modify(pt, false);
		}
		
	}

}
